package com.maiikun.thread_pool;

import com.maiikun.thread_pool.reject.AbortPolicy;
import com.maiikun.thread_pool.reject.DiscardOldestPolicy;
import com.maiikun.thread_pool.reject.RejectHandle;

import java.util.concurrent.*;

public class Main {
    public static void main(String[] args) {
        MyThreadPool myThreadPool = new MyThreadPool(5,7,1, TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(5),new DiscardOldestPolicy());

        for (int i = 0; i < 8; i++) {
            int finalI = i;
            myThreadPool.execute(()->{
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println(Thread.currentThread().getName() + "线程执行了" + finalI);
            });
        }

        System.out.println("主线程未被阻塞");


        new ThreadPoolExecutor(1,1,1,TimeUnit.SECONDS,new LinkedBlockingQueue<>(10),
                Executors.defaultThreadFactory(),new ThreadPoolExecutor.AbortPolicy());
    }
}
